package com.java.handler;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器
 */
public class HandlerSession implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
        Object boosUser = request.getSession().getAttribute("boosUser");
        Object resUser = request.getSession().getAttribute("resUser");
        Object makerAndINOOTUser = request.getSession().getAttribute("makerAndINOOTUser");
        System.out.println("ooo"+boosUser);
//        if(boosUser==null || boosUser.equals("") || resUser==null || resUser.equals("") || makerAndINOOTUser==null || makerAndINOOTUser.equals("")){
//            response.sendRedirect(request.getContextPath()+"/Log");
//            System.out.println("123");
//            return false;
//        }else if(boosUser!=null&&resUser==null&&makerAndINOOTUser==null) {
//            System.out.println("456");
//            return true;
//        }else {
//            return false;
//        }
        if(boosUser!=null&&resUser==null&&makerAndINOOTUser==null || boosUser==null&&resUser!=null&&makerAndINOOTUser==null || boosUser==null&&resUser==null&&makerAndINOOTUser!=null){
            return true;
        }else {
            response.sendRedirect(request.getContextPath()+"/Log");
            return false;
        }

    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
